package com.he.eduservice.controller;


import com.he.commonutils.R;
import com.he.eduservice.entity.course.CourseInfoForm;
import com.he.eduservice.entity.course.CoursePublishVo;
import com.he.eduservice.service.EduCourseService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testhejinyu
 * @since 2021-06-02
 */
@RestController
@RequestMapping("/eduservice/course")
@CrossOrigin
public class EduCourseController {
    @Autowired
    EduCourseService courseService;

    @PostMapping("/addCourse")
    @ApiOperation(value = "课程基本信息")
    public R addCourseInfo(@ApiParam(value = "课程基本信息", required = true) @RequestBody CourseInfoForm data) {
        String CourseId;
        CourseId = courseService.addCourse(data);
        return R.ok().data("courseId", CourseId);
    }

    @GetMapping("/getCourseInfoById/{courseId}")
    @ApiOperation(value = "获取课程基础信息")
    public R getCourseInfoById(@PathVariable("courseId") String courseId){
        CourseInfoForm courseInfoForm = courseService.findCourseInfoByCourseId(courseId);
        return R.ok().data("course",courseInfoForm);
    }

    @PostMapping("/updateCourseInfoById")
    @ApiOperation(value = "修改课程基础信息")
    public R updateCourseInfoById(@RequestBody CourseInfoForm data){
        courseService.updateCourseInfoById(data);
        return R.ok();
    }

    @ApiOperation(value = "根据ID取课程发布信息")
    @GetMapping("/getCoursePublish/{id}")
    public R selectCoursePublishVoById(@PathVariable String id){
        CoursePublishVo coursePublishVo = courseService.selectCoursePublishVoById(id);
        return R.ok().data("coursePublishVo",coursePublishVo);
    }

    @PutMapping("/publishCourseById/{id}")
    public R publishCourseById(@PathVariable String id){
        boolean flag = courseService.publishCourseById(id);
        return R.ok().data("flag",flag);
    }

    //删除课程


}

